package bsf.baseservice.businessmq.producter.loadbalance;

import bsf.baseservice.businessmq.producter.ProducterContext;
import bsf.baseservice.businessmq.model.tb_mqpath_partition_model;
import bsf.baseservice.businessmq.systemruntime.SystemParamConfig;

public abstract class BaseLoadBalance
{
	/** 
	 所有历史出错的分区信息（程序启动后所有的出错分区信息）
	 
	*/
	protected java.util.HashMap<String, ErrorLoadBalancePartitionInfo> allErrorHistoryPartitionInfos = new java.util.HashMap<String, ErrorLoadBalancePartitionInfo>();
	/** 
	 当前出错的分区信息（生产者心跳后,错误的分区将被清空，重新尝试使用，以便故障恢复）
	 
	*/
	protected java.util.HashMap<String, ErrorLoadBalancePartitionInfo> currentErrorPartitionInfos = new java.util.HashMap<String, ErrorLoadBalancePartitionInfo>();
	/** 
	 当前可用的分区信息（故障转移的分区，将被移除）
	 
	*/
	protected  java.util.ArrayList<tb_mqpath_partition_model> getMQPathParitionModels()
	{
		return Context.ProducterInfo.MqPathParitionModel;
	}

	public ProducterContext Context;

	protected Object _errorloglock = new Object();

	public int SendMessageErrorTryAgainCount = SystemParamConfig.Producter_SendMessageError_TryAgainCount;


	public LoadBalancePartitionInfo getLoadBalancePartitionInfo()
	{
		return null;
	}

	public void addError(ErrorLoadBalancePartitionInfo info)
	{
		synchronized(_errorloglock)
		{
			if (!currentErrorPartitionInfos.containsKey(info.getHashCode()))
			{
				currentErrorPartitionInfos.put(info.getHashCode(),info);
			}
			if (!allErrorHistoryPartitionInfos.containsKey(info.getHashCode()))
			{
				allErrorHistoryPartitionInfos.put(info.getHashCode(), info);
			}
		}
	}

	public void clearError()
	{
		synchronized (_errorloglock)
		{
			currentErrorPartitionInfos.clear();
		}
	}
}